//
//  FenxiangDetailViewController.m
//  ToListenPhone
//
//  Created by zhibao on 2023/7/18.
//

#import "FLSHaoPingDetailController.h"

@interface FLSHaoPingDetailController ()

@end

@implementation FLSHaoPingDetailController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.gk_backImage = [UIImage imageNamed:@"arrow_back_white"];
    self.gk_statusBarStyle = UIStatusBarStyleLightContent;
    [self hideNavLine];
    
    UINavigationBarAppearance *appearance = [UINavigationBarAppearance new];
    [appearance configureWithOpaqueBackground];
    appearance.backgroundColor = UIColor.clearColor;
    //去掉导航栏下的阴影线
    appearance.shadowColor = UIColor.clearColor;
    self.gk_navigationBar.standardAppearance = appearance;
    self.gk_navigationBar.scrollEdgeAppearance = self.gk_navigationBar.standardAppearance;
    
    
    UIView *topView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, MY_Screen_W, 283)];
    topView.backgroundColor = MyColor(@"#0084FF");
    self.view.backgroundColor = UIColor.whiteColor;
    [self.view addSubview:topView];
    
    UIImageView *imgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"fulishe_fenxiang_top"]];
    [self.view addSubview:imgView];
    [imgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.view);
        make.top.mas_equalTo(5);
    }];
    
    UILabel *titleLabel = [UILabel new];
    titleLabel.text = @"五星好评";
    titleLabel.textColor = UIColor.whiteColor;
    titleLabel.font = MY_SCALE_SemiboldFONT(30);
    [self.view addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(25);
        make.top.mas_equalTo(113 - 64 + NAVIH);
    }];
    
    UILabel *detailLabel = [UILabel new];
    detailLabel.text = [NSString stringWithFormat:@"好评后可获得 %d 天VIP会员",[MYGlobal share].vipDay];
    detailLabel.textColor = MyColor(@"ffffff");
    detailLabel.font = MY_SCALE_RegularFONT(15);
    [self.view addSubview:detailLabel];
    [detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(titleLabel);
        make.top.equalTo(titleLabel.mas_bottom).offset(13);
    }];
    
    UIView *bottotmView = [[UIView alloc]initWithFrame:CGRectMake(0, 239 - 64 + NAVIH, MY_Screen_W, 200)];
    bottotmView.backgroundColor = UIColor.whiteColor;
    bottotmView.layer.cornerRadius = 20;
    [self.view addSubview:bottotmView];
    
    UILabel *cshuomingLabel = [UILabel new];
    cshuomingLabel.text = @"活动说明";
    cshuomingLabel.textColor = MYBlock;
    cshuomingLabel.font = MY_SCALE_SemiboldFONT(16);
    [self.view addSubview:cshuomingLabel];
    [cshuomingLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(titleLabel);
        make.top.equalTo(bottotmView.mas_top).offset(36);
    }];
    
    UILabel *shuomingLabel = [UILabel new];
    shuomingLabel.text = @"1、用户点击下边的我要好评按钮跳转至苹果应用商店 APP Store 进行五星好评；\n\n 2、好评后返回至APP，系统会自动发放会员权益； \n\n3、每个苹果 ID 用户只能参加一次改活动。";
    shuomingLabel.textColor = MyColor(@"999999");
    shuomingLabel.font = MY_SCALE_RegularFONT(12);
    shuomingLabel.numberOfLines = 0;
    shuomingLabel.lineBreakMode = NSLineBreakByWordWrapping;
    [self.view addSubview:shuomingLabel];
    
    [shuomingLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(titleLabel);
        make.right.mas_equalTo(-20);
        make.top.equalTo(cshuomingLabel.mas_bottom).offset(25);
    }];
    
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.backgroundColor = MyColor(@"#0084FF");
    [btn setTitle:@"我要好评" forState:UIControlStateNormal];
    [btn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(btnclick) forControlEvents:UIControlEventTouchUpInside];
    btn.titleLabel.font = MY_SCALE_SemiboldFONT(16);
    btn.layer.cornerRadius = 23;
    [self.view addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
        make.height.mas_equalTo(46);
        make.top.equalTo(shuomingLabel.mas_bottom).offset(50);
    }];
}

-(void)btnclick{
    
    [[HttpHelper sharedInstance] sendGet:@"api/appstore/5star/review/state" parameters:@{} success:^(NSURLSessionTask * _Nonnull operation, ResponseModel * _Nonnull responseObject) {
        DLog(@"result==%@",responseObject.data);
        if(responseObject.code == 1){
            if([responseObject.data[@"data"][@"state"] intValue] == 1){
                [Helper alertShowWithTitle:LocalizedString(@"提示") withContent:@"您已参加过此活动了，把这机会让给别人吧~"
                              withBtnTitle:LocalizedString(@"我知道了") withCancel:^(BOOL flag) {
                }];
            }else{
                NSString * urlStr = [NSString stringWithFormat:@"itms-apps://itunes.apple.com/app/id%@?action=write-review",@"6468908434"];
                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlStr] options:@{UIApplicationOpenURLOptionsSourceApplicationKey:@YES} completionHandler:^(BOOL success) {
                    DLog(@"sucess==%d",success);
                    if(success){
                        [[HttpHelper sharedInstance] sendPost:@"api/appstore/5star/review" parameters:@{} success:^(NSURLSessionTask * _Nonnull operation, ResponseModel * _Nonnull responseObject1) {
                            DLog(@"responseObject1==%@",responseObject1.data);
                            if(responseObject1.code == 1){
                                NSString *result = responseObject1.data[@"data"][@"result"];
                                NSArray *resultArray = [result componentsSeparatedByString:@"-"];
                                [Helper alertShowWithTitle:LocalizedString(@"提示") withContent:[NSString stringWithFormat:@"恭喜获得%@天会员",resultArray.firstObject]
                                              withBtnTitle:LocalizedString(@"我知道了") withCancel:^(BOOL flag) {
                                }];
                            }
                        } failure:^(NSURLSessionTask * _Nonnull operation, NSError * _Nonnull error) {
                            
                        }];
                    }
                }];
            }
        }
    } failure:^(NSURLSessionTask * _Nonnull operation, NSError * _Nonnull error) {
        
    }];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
